package com.gmq.chapter01.controller;

/**
 * Created by gmq on 2017/08/08.
 * 非线程安全问题
 *
 * @version 1.0
 * @since 2017/08/08 16:12
 */
public class LoginServlet {

    private static String usernameRef;
    private static String passwordRef;

    // 非线程安全，加上synchronized,既可以了保证线程安全，排队进入
    synchronized public static void doPost(String username, String password) {
        try {
            usernameRef = username;
            if (username.equals("a")) {
                Thread.sleep(5000);
            }
            passwordRef = password;
            System.out.println("username=" + usernameRef + "  password=" + passwordRef);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}
